﻿using System.Text.RegularExpressions;

namespace Common
{
    public static class CommonStringExtension
    {
        public static string ToTitleCase(this string text)
        {
            var cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
            return cultureInfo.TextInfo.ToTitleCase(text.ToLower());
        }

        public static string ReplaceWordChars(this string text)
        {
            var s = text;

            // smart single quotes and apostrophe
            s = Regex.Replace(s, "[\u2018|\u2019|\u201A]", "'");
            // smart double quotes
            s = Regex.Replace(s, "[\u201C|\u201D|\u201E]", "\"");
            // ellipsis
            s = Regex.Replace(s, "\u2026", "...");
            // dashes
            s = Regex.Replace(s, "[\u2013|\u2014]", "-");
            // circumflex
            s = Regex.Replace(s, "\u02C6", "^");
            // open angle bracket
            s = Regex.Replace(s, "\u2039", "<");
            // close angle bracket
            s = Regex.Replace(s, "\u203A", ">");
            // spaces
            s = Regex.Replace(s, "[\u02DC|\u00A0]", " ");

            s = s.Replace("« ", "\"");
            s = s.Replace(" »", "\"");

            s = s.Replace('«', '"');
            s = s.Replace('»', '"');

            s = s.Replace('“', '"');
            s = s.Replace('”', '"');
            

            return s;
        }
    }
}